import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class code3_2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();

        int[] dp = new int[n+1];

        dp[0] = 0;
        dp[1] = 1;
        int ret = n-1;

        for (int i = 2; i < n; i++) {
            dp[i] = dp[i-1] + dp[i-2];
            ret = Math.min(ret,Math.abs(dp[i]-n));
            if(dp[i] > n) {
                ret = Math.min(ret,Math.abs(dp[i]-n));
                break;
            }
        }

        System.out.println(ret);
    }
}